package com.xiaoxi.exam.controller;

import cn.xinzhili.xutils.core.http.Response;
import com.xiaoxi.exam.bean.response.ToeflProvinceCityResponse;
import com.xiaoxi.exam.service.ExamService;
import com.xiaoxi.exam.service.ToeflSchoolService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Api(description = "TOEFL考位信息接口")
@RequestMapping("/toefl")
public class ToeflExamInfoController {

  @Autowired
  private ExamService examService;

  @Autowired
  private ToeflSchoolService toeflSchoolService;


  @ApiOperation(value = "根据省份城市信息", notes = "查询考试城市")
  @GetMapping("/city")
  public Response getCityList() {
    ToeflProvinceCityResponse response = new ToeflProvinceCityResponse();
    response.setResults(toeflSchoolService.getCities());
    return Response.instanceSuccess(response);
  }

  @ApiOperation(value = "根据省份城市获取考点", notes = "根据省份城市获取考点")
  @ApiImplicitParams({
      @ApiImplicitParam(name = "province", value = "省份", dataType = "String", paramType = "query"),
      @ApiImplicitParam(name = "city", value = "城市", dataType = "String", paramType = "query")
  })
  @GetMapping("/school")
  public Response getSchoolList(
      @RequestParam(value = "province", defaultValue = "北京") String province,
      @RequestParam(value = "city", defaultValue = "北京") String city) {
    return Response.instanceSuccess()
        .withDataEntry("schools", toeflSchoolService.getSchools(province, city));
  }

  @ApiOperation(value = "根据城市考点获取考试时间", notes = "根据城市考点获取考试时间")
  @GetMapping("/exam/time")
  public Response getExamTime() {
    List<String> examTimeByCityAndSchool = examService.getExamTimeByCityAndSchool();
    return Response.instanceSuccess().withDataEntry("time", examTimeByCityAndSchool);

  }

}
